import { BasicColumn, useRender, FormSchema } from '/@/components/Table';
import moment from 'moment';
import { DICT_TYPE, getDictOptions } from '/@/utils/dict';

export const columns: BasicColumn[] = [
  {
    title: '流程编号',
    dataIndex: 'id',
  },
  {
    title: '流程名称',
    dataIndex: 'name',
  },
  {
    title: '流程分类',
    dataIndex: 'category',
    customRender: ({ text }) => {
      return useRender.renderDict(text, DICT_TYPE.BPM_MODEL_CATEGORY);
    },
  },
  {
    title: '当前审批任务',
    dataIndex: 'taskName',
    customRender: ({ record }) => {
      if (record.tasks && record.tasks.length > 0) {
        const texts: any[] = [];
        record.tasks.forEach((val) => {
          texts.push(val.name);
        });
        return useRender.renderTags(texts);
      }
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    customRender: ({ text }) => {
      return useRender.renderDict(text, DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS);
    },
  },
  {
    title: '结果',
    dataIndex: 'result',
    customRender: ({ text }) => {
      return useRender.renderDict(text, DICT_TYPE.BPM_PROCESS_INSTANCE_RESULT);
    },
  },
  {
    title: '提交时间',
    dataIndex: 'createTime',
    customRender: ({ record }) => {
      const time = record.createTime;
      return time ? moment(time).format('YYYY-MM-DD HH:mm:ss') : '-';
    },
  },
  {
    title: '结束时间',
    dataIndex: 'endTime',
    customRender: ({ record }) => {
      const time = record.endTime;
      return time ? moment(time).format('YYYY-MM-DD HH:mm:ss') : '-';
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '流程名称',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: ({ tableAction }) => {
      return {
        onPressEnter: () => {
          const { reload } = tableAction;
          reload();
        },
      };
    },
  },
  {
    label: '流程分类',
    field: 'category',
    component: 'Select',
    componentProps: {
      options: getDictOptions(DICT_TYPE.BPM_MODEL_CATEGORY),
    },
    colProps: { span: 8 },
  },
  {
    label: '状态',
    field: 'status',
    component: 'Select',
    componentProps: {
      options: getDictOptions(DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS),
    },
    colProps: { span: 8 },
  },
  {
    label: '结果',
    field: 'result',
    component: 'Select',
    componentProps: {
      options: getDictOptions(DICT_TYPE.BPM_PROCESS_INSTANCE_RESULT),
    },
    colProps: { span: 8 },
  },
  {
    field: 'createTime',
    label: '提交时间',
    component: 'RangePicker',
    colProps: { span: 8 },
    componentProps: {
      valueFormat: 'X',
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '角色名称',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入角色名称',
    },
  },
  {
    field: 'code',
    label: '角色编码',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入角色编码',
    },
  },
  {
    field: 'sort',
    label: '序号',
    component: 'Input',
    required: true,
    defaultValue: '255',
    componentProps: {
      placeholder: '请输入角色序号',
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入备注',
    },
  },
];
